<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>用户添加</h2>
<hr>
<form id="user-form">
  <input type="number" name="id" placeholder="请输入用户id"></input><br>
  <input type="text" name="name" placeholder="请输入用户名"></input><br>
  <input type="number" name="age" placeholder="请输入用户年龄"></input><br>
  <input type="email" name="email" placeholder="请输入邮箱"></input><br>
  <button>确认添加</button>
</form>
<script src="js/jquery-3.7.1.min.js"></script>
<script>
  $(function (){
    //ajax:异步请求技术（局部刷新技术）
    $('button').on('click',function(){
      //获取表单数据转换为查询字符串？id=xx&name=xxx&age=xx&email=xx
      let data=$('#user-form').serialize()
      $.get('/user/add',data,function (resp){
        if(resp){
          alert('添加成功')
          location.href='index.html'
          return;
        }
        alert('添加失败')
      })
    })
  })
</script>
</body>
</html>